package orm

import (
	_ "github.com/go-sql-driver/mysql"
	"github.com/go-xorm/xorm"
	"github.com/jinzhu/configor"
)

var config = struct {
	Mysql struct {
		Host     string
		Port     string
		User     string
		Password string
		Database string
	}
}{}

var Engine *xorm.Engine

var models []interface{}

var migrations []string

func Connect() (*xorm.Engine, error) {
	configor.Load(&config, "conf/config.yml")
	client := config.Mysql
	connectionStr := client.User + ":" + client.Password + "@tcp(" + client.Host + ":" + client.Port + ")/" + client.Database + "?charset=utf8"

	engine, err := xorm.NewEngine("mysql", connectionStr)
	engine.ShowSQL(true)
	Engine = engine

	return engine, err
}

func RegisterModel(model interface{}) {
	models = append(models, model)
}

func AutoMigrate() {

}
